/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * VentanaModificarColectivo.java
 *
 * Created on 14-may-2012, 12:17:55
 */
package gui;

import ClasesAModificar.ColectivoModificar;
import javax.swing.JOptionPane;
import src.BorraCeldas;
import src.FuncionesModificar;

/**
 *
 * @author usuario_local
 */
public class VentanaModificarColectivo extends javax.swing.JFrame {

    int elem;
    VentanaModificar vm;
    
    /** Creates new form VentanaModificarColectivo */
    public VentanaModificarColectivo(int elem, VentanaModificar vm,ColectivoModificar CM) {
        this.elem = elem;
        this.vm = vm;
        initComponents();
        inicializarContenido(CM);
        this.CM = CM;
    }
    
    private void inicializarContenido(ColectivoModificar CM)
    {
        jTextField_vcoDescripcion.setText(CM.getDesc());
        jTextField_vcoNombre.setText(CM.getNombre());
    }

    private boolean comprobar(){
        String mensaje = "";
        boolean resultado = false;
        
        if (this.jTextField_vcoNombre.getText().equals(""))
            mensaje += "Por favor rellene el campo de nombre\n\n";
        if (this.jTextField_vcoDescripcion.getText().equals(""))
            mensaje += "Por favor rellene el campo de descripción\n\n";
 
        if ("".equals(mensaje))
            resultado =true;
        else
            JOptionPane.showMessageDialog(null, mensaje);
        
        return resultado;
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel_vcoNombre = new javax.swing.JLabel();
        jTextField_vcoNombre = new javax.swing.JTextField();
        jLabel_vcoDescripcion = new javax.swing.JLabel();
        jTextField_vcoDescripcion = new javax.swing.JTextField();
        jButton_VMCFichero = new javax.swing.JButton();
        jButton_VMOTerminar = new javax.swing.JButton();
        jButton_VMCEliminar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);

        jLabel_vcoNombre.setText("Nombre");

        jLabel_vcoDescripcion.setText("Descripcion");

        jButton_VMCFichero.setText("Rel. Fichero");
        jButton_VMCFichero.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton_VMCFicheroMouseClicked(evt);
            }
        });

        jButton_VMOTerminar.setText("Terminar");
        jButton_VMOTerminar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton_VMOTerminarMouseClicked(evt);
            }
        });

        jButton_VMCEliminar.setText("Eliminar");
        jButton_VMCEliminar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton_VMCEliminarMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jLabel_vcoNombre)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jTextField_vcoNombre, javax.swing.GroupLayout.DEFAULT_SIZE, 384, Short.MAX_VALUE))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jLabel_vcoDescripcion)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jTextField_vcoDescripcion, javax.swing.GroupLayout.DEFAULT_SIZE, 367, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGap(0, 342, Short.MAX_VALUE)
                .addComponent(jButton_VMCFichero))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(148, 148, 148)
                .addComponent(jButton_VMCEliminar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton_VMOTerminar)
                .addContainerGap(133, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel_vcoNombre)
                    .addComponent(jTextField_vcoNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel_vcoDescripcion)
                    .addComponent(jTextField_vcoDescripcion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton_VMCFichero)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton_VMOTerminar)
                    .addComponent(jButton_VMCEliminar))
                .addGap(0, 11, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton_VMOTerminarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton_VMOTerminarMouseClicked
        // TODO add your handling code here:
        if(comprobar()){
            vm.setVisible(true);
            this.setVisible(false);

            CM.setDesc(jTextField_vcoDescripcion.getText());
            CM.setNombre(jTextField_vcoNombre.getText());

            FuncionesModificar.modificarColectivo(CM);
            this.dispose();
        }
    }//GEN-LAST:event_jButton_VMOTerminarMouseClicked

    private void jButton_VMCFicheroMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton_VMCFicheroMouseClicked
        // TODO add your handling code here:
        VentanaModificarRelaciones vmr = new VentanaModificarRelaciones(5,this,CM.getListaFicheros(),CM.getIdCol());
        vmr.setVisible(true);
        this.setVisible(false);
    }//GEN-LAST:event_jButton_VMCFicheroMouseClicked

    private void jButton_VMCEliminarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton_VMCEliminarMouseClicked
        vm.setVisible(true);
        this.setVisible(false);
        BorraCeldas.BorrarColectivo(CM.getIdCol());
        this.dispose();
    }//GEN-LAST:event_jButton_VMCEliminarMouseClicked

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton_VMCEliminar;
    private javax.swing.JButton jButton_VMCFichero;
    private javax.swing.JButton jButton_VMOTerminar;
    private javax.swing.JLabel jLabel_vcoDescripcion;
    private javax.swing.JLabel jLabel_vcoNombre;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JTextField jTextField_vcoDescripcion;
    private javax.swing.JTextField jTextField_vcoNombre;
    // End of variables declaration//GEN-END:variables
    private ColectivoModificar CM;
}
